import { defineEventHandler, readBody } from "h3"
import { UserService } from "../../../services/userService"

export default defineEventHandler(async (event) => {
  const user = event.context.user
  const { name, avatar } = await readBody(event)

  const updatedUser = await UserService.updateUser(user.id, {
    name,
    avatar,
  })

  return {
    id: updatedUser.id,
    email: updatedUser.email,
    name: updatedUser.name,
    avatar: updatedUser.avatar,
  }
})
